﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Wizzard
{
    class Wizzard
    {
        Texture2D textura;
        public Rectangle area;
        float grav = 0;
        Chao chao;
        int vel = 5;

        bool pulando;

        public Wizzard(ContentManager content, GameWindow window)
        {
            textura = content.Load<Texture2D>("Wiz");
            area.Width = textura.Width;
            area.Height = textura.Height;
            area.X = window.ClientBounds.Width / 2 - textura.Width / 2;
            area.Y = 300;
            chao = new Chao(content, window);
        }

        public void Update(GameTime gameTime, KeyboardState teclado)
        {

            foreach (Fogo tiro in Fogo.tiros)
            {
                if (area.Intersects(tiro.posicao))
                {
                    Game1.estado_atual = Game1.estados.GAME_OVER;
                }
            }

            grav += 0.4f;
            if (grav > 10) grav = 10;
            area.Y += (int)grav;
            if (teclado.IsKeyDown(Keys.A))
            {
                area.X -= vel;
            }
            if (teclado.IsKeyDown(Keys.D))
            {
                area.X += vel;
            }
            if (area.Intersects(chao.area))
            {
                area.Y -= (int)grav;
                pulando = false;
            }
            if ((teclado.IsKeyDown(Keys.Space) || teclado.IsKeyDown(Keys.W)) && pulando == false)
            {
                grav = -12;
                pulando = true;
            }
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(textura, area, Color.White);
            chao.Draw(gameTime, spriteBatch);
        }
    }
}
